using System;
using System.Collections.Generic;
using System.Text;

namespace Eve.Data
{
    public class AssemblyLine : EveProperty
    {
        private int assemblyLineTypeId;
        private int containerId;
        private DateTime nextFreeTime;
        private int uiGroupingId;
        private double costInstall;
        private double costPerHour;
        private int restrictionMask;
        private double discountPerGoodStandingPoint;
        private double surchargePerBadStandingPoint;
        private double minimumStanding;
        private double minimumCharSecurity;
        private double minimumCorpSecurity;
        private double maximumCharSecurity;
        private double maximumCorpSecurity;
        private int ownerId;
        private int oldContainerId;
        private int oldOwnerId;
        private int activityId;

        private AssemblyLineType assemblyLineType;
        private EveObject container;
        private EveObject owner;
        private EveObject oldContainer;
        private EveObject oldOwner;
        private RAMActivity activity;

        public AssemblyLineType AssemblyLineType
        {
            get
            {
                if (assemblyLineType == null)
                    assemblyLineType = new AssemblyLineType(db, assemblyLineTypeId);
                return assemblyLineType;
            }
        }
        public EveObject Container
        {
            get
            {
                if (container == null)
                    container = EveData.GetObject(db, containerId);
                return container;
            }
        }
        public DateTime NextFreeTime
        {
            get { return nextFreeTime; }
        }
        public int UIGrouping
        {
            get { return uiGroupingId; }
        }
        public double InstallCost
        {
            get { return costInstall; }
        }
        public double CostPerHour
        {
            get { return costPerHour; }
        }
        public int RestrictionMask
        {
            get { return restrictionMask; }
        }
        public double GoodStandingDiscount
        {
            get { return discountPerGoodStandingPoint; }
        }
        public double BadStandingSurcharge
        {
            get { return surchargePerBadStandingPoint; }
        }
        public double MinimumStanding
        {
            get { return minimumStanding; }
        }
        public double MinimumCharacterSecurity
        {
            get { return minimumCharSecurity; }
        }
        public double MinimumCorporationSecurity
        {
            get { return minimumCorpSecurity; }
        }
        public double MaximumCharacterSecurity
        {
            get { return maximumCharSecurity; }
        }
        public double MaximumCorporationSecurity
        {
            get { return maximumCorpSecurity; }
        }
        public EveObject Owner
        {
            get
            {
                if (owner == null)
                    owner = EveData.GetObject(db, ownerId);
                return owner;
            }
        }
        public EveObject OldContainer
        {
            get
            {
                if (oldContainer == null)
                    oldContainer = EveData.GetObject(db, oldContainerId);
                return oldContainer;
            }
        }
        public EveObject OldOwner
        {
            get
            {
                if (oldOwner == null)
                    oldOwner = EveData.GetObject(db, oldOwnerId);
                return oldOwner;
            }
        }
        public RAMActivity Activity
        {
            get
            {
                if (activity == null)
                    activity = new RAMActivity(db, activityId);
                return activity;
            }
        }

        internal AssemblyLine(DbDataRow dr)
            : base(dr.Database, EvePropertyType.AssemblyLine, dr["assemblyLineID"])
        {
            Fill(dr);
        }
        internal AssemblyLine(Database db, int id)
            : base(db, EvePropertyType.AssemblyLine, id)
        {
            Fill(db.ExecuteSingle("SELECT * FROM ramAssemblyLines WHERE assemblyLineID=" + id));
        }

        private void Fill(DbDataRow dr)
        {
            assemblyLineTypeId = dr["assemblyLineTypeID"];
            containerId = dr["containerID"];
            nextFreeTime = dr["nextFreeTime"];
            uiGroupingId = dr["UIGroupingID"];
            costInstall = dr["costInstall"];
            costPerHour = dr["costPerHour"];
            restrictionMask = dr["restrictionMask"];
            discountPerGoodStandingPoint = dr["discountPerGoodStandingPoint"];
            surchargePerBadStandingPoint = dr["surchargePerBadStandingPoint"];
            minimumStanding = dr["minimumStanding"];
            minimumCharSecurity = dr["minimumCharSecurity"];
            minimumCorpSecurity = dr["minimumCorpSecurity"];
            maximumCharSecurity = dr["maximumCharSecurity"];
            maximumCorpSecurity = dr["maximumCorpSecurity"];
            ownerId = dr["ownerID"];
            oldContainerId = dr["oldContainerID"];
            oldOwnerId = dr["oldOwnerID"];
            activityId = dr["activityID"];
        }
    }
}
